﻿using Entity.ERP.DTO.SaleDeliveryOrder;
using Entity.ERP.View.SaleDeliveryOrder;
using Entity.ERP.View.SaleDeliveryOrderItem;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.ERP;

namespace AnQinManagermentBackendAPI.Controller.ERP
{
    /// <summary>
    /// 销售发货单管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    //[Authorize]
    public class SaleDeliveryController : ControllerBase
    {
        private readonly SaleDeliveryService _saleDeliveryService;

        public SaleDeliveryController(SaleDeliveryService saleDeliveryService)
        {
            _saleDeliveryService = saleDeliveryService;
        }

        /// <summary>
        /// 获取销售发货单列表
        /// </summary>
        [HttpGet]
        [ProducesResponseType(typeof(SaleDeliveryOrderView), 200)]
        public async Task<IActionResult> GetSaleDeliveryList([FromQuery] SaleDeliverySearchDTO saleDeliveryOrderSearchDTO)
        {
            var response = await _saleDeliveryService.GetSaleDeliveryList(saleDeliveryOrderSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 获取销售发货单子单列表
        /// </summary>
        [HttpGet("item")]
        [ProducesResponseType(typeof(SaleDeliveryOrderItemView), 200)]
        public async Task<IActionResult> GetSaleDeliveryOrderItemList([FromQuery] SaleDeliveryItemSearchDTO saleDeliveryItemSearchDTO)
        {
            var response = await _saleDeliveryService.GetSaleDeliveryOrderItemList(saleDeliveryItemSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增销售发货单
        /// </summary>
        [HttpPost]
        public async Task<IActionResult> AddSaleDeliveryOrder([FromBody] SaleDeliveryAddDTO saleDeliveryAddDTO)
        {
            var response = await _saleDeliveryService.AddSaleDeliveryOrder(saleDeliveryAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 编辑销售发货单
        /// </summary>
        [HttpPut]
        public async Task<IActionResult> PutSaleDeliveryOrder([FromBody] SaleDeliveryUpdateDTO saleDeliveryUpdateDTO)
        {
            var response = await _saleDeliveryService.PutSaleDeliveryOrder(saleDeliveryUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除销售发货单
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteSaleDeliveryOrder(string Id)
        {
            var response = await _saleDeliveryService.DeleteSaleDeliveryOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 销售发货单 - 审核通过
        /// </summary>
        [HttpPost("Pass")]
        public async Task<IActionResult> PassSaleDeliveryOrder(string Id)
        {
            var response = await _saleDeliveryService.PassSaleDeliveryOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 销售发货单 - 审核不通过
        /// </summary>
        [HttpPost("UnPass")]
        public async Task<IActionResult> UnPassSaleDeliveryOrder(string Id)
        {
            var response = await _saleDeliveryService.UnPassSaleDeliveryOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 销售发货单 - 反审核
        /// </summary>
        [HttpPost("CancelPass")]
        public async Task<IActionResult> CancelPassSaleDeliveryOrder(string Id)
        {
            var response = await _saleDeliveryService.CancelPassSaleDeliveryOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 推送
        /// </summary>
        [HttpPost("Push")]
        public async Task<IActionResult> PushSaleDeliveryOrder(string Id)
        {
            var response = await _saleDeliveryService.PushSaleDeliveryOrder(Id);
            return StatusCode(response.Status, response);
        }

    }
}
